// lightpil.txt
// A magic pillar that guards a loc. It needs a
// force pillar closer than 10 spaces away from it.
//Cells: 0, 1 - target loc.
beginterrainscript;
variables;
     int severity;
     int wait = 0;
     int my_cur_mess;
     int sr = -1;
body;
beginstate INIT_STATE;
    set_script_mode(2);
break;
beginstate START_STATE;
    my_cur_mess = my_current_message();
    if ((char_on_loc(get_memory_cell(0), get_memory_cell(1)) != -1)  && (wait == 0))
    {    
        broadcast_terrain_message(10, my_loc_x() * 100 + my_loc_y()); 
        wait = 1; 
        end();
    }
    if ((wait == 1) && (my_current_message() == -11))
    {
        broadcast_terrain_message(10, my_number() * 100);
        wait = 2;
        end();
    }
    if ((my_cur_mess != -1) && (my_cur_mess != my_loc_x() * 100 + my_loc_y()) && (wait == 2))
    {
        if (my_cur_mess != -1)
            sr = my_cur_mess;
        severity = sr + 1;    
        put_jagged_zap(my_loc_x(), my_loc_y(), get_memory_cell(0), get_memory_cell(1), 6);
        put_boom_on_space(get_memory_cell(0), get_memory_cell(1), 3, 0);
        put_sparkles_on_space(get_memory_cell(0), get_memory_cell(1), 11, 11);
        run_animation_sound(164);
        if (char_on_loc(get_memory_cell(0), get_memory_cell(1)) != -1)
        {
            damage_char(char_on_loc(get_memory_cell(0), get_memory_cell(1)), severity * 5, 3);
            set_char_status(char_on_loc(get_memory_cell(0), get_memory_cell(1)), 11, severity, 0, 1);
        }
        wait = 0;
        my_cur_mess = 0;
    }
break;